package com.loong.scala.jsonregex

import java.io.{File, PrintWriter}

import com.loong.java.json.regex.FastJson

import scala.io.Source

/**
  * Created by 梁浩峰 on 2016/9/14 14:10.
  */
object JsonTestV2 {
  def main(args: Array[String]): Unit = {
    val json ="""[{"send_time":"Thu Sep 08 16:04:19 CST 2016","send_log_info":"(none) : {\"dt\":\"VENUS_IDS_0700R0300B20150803200223\",\"level\":10,\"id\":\"152320138\",\"type\":\"Alert Log\",\"time\":1473321859072,\"source\":{\"ip\":\"10.1.1.254\",\"port\":0,\"mac\":\"00-25-b4-d9-26-80\"},\"destination\":{\"ip\":\"10.1.1.15\",\"port\":0,\"mac\":\"6c-f0-49-26-10-7c\"},\"protocol\":\"ICMP\",\"subject\":\"ICMP_PING_回答事件\",\"message\":\"nic=3;类型=0;\"}","log_level":"WARN","send_log_address":"10.1.255.223"}]""".toString

    val newjson = JsonRegexUtils.jsonActionAll(json,"""\(none\)\s:\s""", "")

    val value = FastJson.jsonRegx(newjson)




     println(value)

//    logJson()
  }

  def logJson(): Unit = {
    val data = Source.fromFile("D:/logdata/oldlog").getLines()
    val writer = new PrintWriter(new File("D:/logdata/logjsonregex"))
    var count = 0;
    val start = System.currentTimeMillis()
    data.foreach { str =>
      val newjson = JsonRegexUtils.jsonActionAll(str,"""\(none\)\s:\s""", "")
//      val exejson = JsonRegexUtils.jsonActionAll(newjson,""""","log_level""",""","log_level""")
      val value = FastJson.jsonRegx(newjson)
      if (value != null)
        writer.write(value._2 + "\n")
      count = count + 1
    }
    val time = System.currentTimeMillis() - start
    println(time)
    println(count)
    println(count.toDouble / time.toDouble)
    writer.close()

  }


}
